//
// Created by zuo on 2024/7/1.
// 题目链接 https://www.lanqiao.cn/problems/1531/learning/?page=1&first_category_id=1&problem_id=1531
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

map<string, vector<string>> mp; // 一个城市 好多单号
vector<string> citys; // 城市间的顺序

int main()
{
    ll n;
    cin >> n;


    for (int i = 0; i < n; i++)
    {
        string num, city;
        cin >> num >> city;
        if (!mp.count(city)) citys.push_back(city); // 如果 mp里面没有城市  就加入到城市列表里  同时加入mp  有的话就只加入num 不加入city
        mp[city].push_back(num);
    }

    for (const auto& city : citys)
    {
        cout << city << ' ' << mp[city].size() << '\n';
        for (const auto& i : mp[city])
        {
            cout << i << '\n';
        }
    }


    return 0;
}
